import { cgRequest as request } from '@/service'

interface ResultType {
  result: {
    resultCode: string
    resultMessage: string
  }
  data: object
}

/** 适配接口返回结果 */
function adapter(obj: ResultType) {
  if (obj.result.resultCode == '000000') {
    return obj.data
  }
  throw new Error(obj?.result?.resultMessage)
}

/** 账号密码登录 */
export const cgLogin = (data?: any) =>
  request.post(`/pc-login/login`, data).then((res) => adapter(res as any))

/** 查询消防救援机构树 */
export const cgQueryFireControlTree = (params?: any) =>
  request
    .get(`/jc-xfjg-jyjg-model/queryJcXfjgJyjgTree`, { params })
    .then((res) => adapter(res as any))

/** 根据机构id查询全部机构列表 */
export const cgJgidQueryJgList = (params?: any) =>
  request
    .get(`/jc-xfjg-jyjg-model/queryJcXfjgJyjgInfo`, { params })
    .then((res) => adapter(res as any))

/** 查询全部机构列表 */
export const cgQueryJgList = (params?: any) =>
  request
    .get(`/jc-xfjg-jyjg-model/queryJcXfjgJyjgList`, { params })
    .then((res) => adapter(res as any))

/** 根据机构id查询车辆列表 */
export const cgJgIdQueryClxxList = (params?: any) =>
  request.get(`/jc-clxx-model/query/clxx`, { params }).then((res) => adapter(res as any))

/** 查询全部车辆列表 */
export const cgQueryClxxList = (params?: any) =>
  request.get(`/jc-clxx-model/query/page/clxx`, { params }).then((res) => adapter(res as any))

/** 修改车辆信息 */
export const cgEditClxx = (data?: any) =>
  request.post(`/jc-clxx-model/update/clxx`, data).then((res) => adapter(res as any))

/** 根据机构id查询视频监控列表*/
export const cgJgIdQuerySpjkxxList = (params?: any) =>
  request.get(`/dmt-jksp-hp-model/query/jksp`, { params }).then((res) => adapter(res as any))

/** 查询全部视频监控列表 */
export const cgQuerySpjkxxList = (params?: any) =>
  request.get(`/dmt-jksp-hp-model/query/page/jksp`, { params }).then((res) => adapter(res as any))

/** 修改视频监控信息 */
export const cgEditSpjkxx = (data?: any) =>
  request.post(`/dmt-jksp-hp-model/update/jksp`, data).then((res) => adapter(res as any))

/** 获取视频监控地址 */
export const cgQueryVideoSrc = (params?: any) =>
  request.get(`/dmt-jksp-hp-model/start/jksp`, { params }).then((res) => adapter(res as any))
